package cn.antblog.dealData.util;

import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiConsumer;

/**
 * @author yangjy
 * @version 1.0
 * @description: 遍历实体类 接口
 * @date 2022/10/21 15:35
 */
public interface IEach<K, V> {

    Set<Map.Entry<K, V>> entrySet();

    default void forEach(BiConsumer<? super K, ? super V> action) {
        Objects.requireNonNull(action);
        for (Map.Entry<K, V> entry : entrySet()) {
            K k;
            V v;
            try {
                k = entry.getKey();
                v = entry.getValue();
            } catch (IllegalStateException ise) {
                // error
                throw new ConcurrentModificationException(ise);
            }
            action.accept(k, v);
        }
    }

}
